var app = getApp();
var hostURL = app.globalData1.hostURL;
var ImageURL = app.globalData1.ImageURL;
Page({

  data: {

    publishLists: [],
  },


  getPublishList: function () {

    let that = this;
    wx.getStorageSync("userInfo").id
    wx.request({
      url: hostURL + 'sharedplatform-web/sourceDetail/findDetailByUserId.action',
      method: 'post',
      data: {
        userId: wx.getStorageSync("userInfo").id,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        if (res.data.errno == 0) {
          that.setData({
            publishLists: res.data.sourceDetailList,
          })
         
          wx.setStorageSync('mypublish', res.data.sourceDetailList)

          console.log(wx.getStorageSync('mypublish'))
          
          console.log(res.data.sourceDetailList)
        }
        else if (res.data.errno == 1) {
          wx.showToast({
            title: '查询个人发布信息失败 ',
          })
        }
      }
    })
  },

  onLoad: function (options) {

    this.getPublishList();
  },

  // openPublish: function () {
  //   var sourceId = e.currentTarget.dataset.id
  //   console.log(sourceId)
  //   wx.navigateTo({
  //     url: "/pages/goods/goods?sourceId=" + e.currentTarget.dataset.id,
  //   })


  // },

  //删除个人发布信息
  todelete:function(e){
    var sourceId  = e.target.dataset.id
    console.log(",,"+sourceId)
wx.request({
  url: hostURL +'/sharedplatform-web/publish/removePublish.action',
  method: 'get',
  data: {
    source_id: sourceId,
  },
  header: {
    'content-type': 'application/x-www-form-urlencoded'
  },
  success: function (res) {

   if(res.data.errno==1){
     wx.showToast({
       title: '删除失败！ ',
     })
   }
   else{
    
     wx.showToast({
       title: '删除成功！',
     })
     var page = getCurrentPages().pop();
     if (page == undefined || page == null) return;
     page.onLoad()
   }
  
  }
})

},
//修改我的发布信息
  toedit:function(e){
   var index = e.target.dataset.id;
   console.log(",,"+index)
   wx.navigateTo({
  url: '../changeInfo/changeInfo?index='+index,
})

  }



})